package com.pybox.api;

import com.pybox.dto.*;
import com.pybox.service.TVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
* 描述：Tversion Api
* @author wuyingkai
* @date 2018-09-15
*/

@Slf4j
@RequestMapping("/TVersion")
@Api(tags = "TVersion管理接口", description = "TVersion管理接口")
@RestController
public class TVersionApi {

    @Autowired
    private TVersionService service;


    @ApiOperation(value = "创建Tversion", notes = "创建Tversion")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TVersionDto dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除Tversion", notes = "删除Tversion")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "Tversion id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新Tversion", notes = "更新Tversion")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "Tversion id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TVersionDto dto) {
        service.update(id, dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询Tversion", notes = "查询Tversion")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "Tversion id", dataType = "String", paramType = "path")
    public Result<TVersionDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询Tversion", notes = "分页查询Tversion")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "id", value = "id", dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "customerId", value = "customerId", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "hdVersion", value = "hdVersion", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "swVersion", value = "swVersion", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "fpVersion", value = "fpVersion", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TVersionDto>> page(
                        @RequestParam(required = false) Integer id,
                        @RequestParam(required = false) String customerId,
                        @RequestParam(required = false) String fpVersion,
                        @RequestParam(required = false) String swVersion,
                        @RequestParam(required = false) String hdVersion,
                    @RequestParam(required = true) Integer pageNo,
                    @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();

                params.put("hdVersion",hdVersion);
                params.put("customerId",customerId);
                params.put("fpVersion",fpVersion);
                params.put("swVersion",swVersion);
        return Result.ok(service.page(pageNo, pageSize, params));
    }

}